package com.cmrx.model.service.impl;

import com.cmrx.model.dao.AnalysisDao;
import com.cmrx.model.dao.LoginDao;
import com.cmrx.model.dao.OpSceneAnalysisDao;
import com.cmrx.model.dao.SysdictDao;
import com.cmrx.model.entity.*;
import com.cmrx.model.service.AnalysisService;
import com.cmrx.model.service.SysdictService;
import com.cmrx.model.util.UUIDUtil;
import com.cmrx.model.vo.AnalysisVo;
import com.cmrx.model.vo.DictVo;
import com.github.pagehelper.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;


@Service
@Transactional
public class AnalysisServiceImpl implements AnalysisService {
	
	@Autowired 
	private AnalysisDao analysisDao;

    @Autowired
    private SysdictService sysdictService;

    @Autowired
    private OpSceneAnalysisDao opSceneAnalysisDao;

    @Autowired
    private SysdictDao sysdictDao;

    @Autowired
    private LoginDao loginDao;

	@Override
	public AnalysisSuggestion selectAnalysisSuggestionById(CaseDetail caseDetail,String techid) {
		
		AnalysisSuggestion analysisSuggestion = analysisDao.selectAnalysisSuggestionById(caseDetail);
		if(analysisSuggestion!=null && StringUtil.isNotEmpty(analysisSuggestion.getId())) {
//			analysisSuggestion.setCommissionTools(analysisDao.seleCommissionTools(analysisSuggestion.getId()));
            analysisSuggestion.setCommissionTools(analysisDao.seleCommissionTools(analysisSuggestion.getZId()));
		}
		String casetype=caseDetail.getCase_type();
		String regionalism=caseDetail.getScene_regionalism();


        if(StringUtil.isNotEmpty(casetype) && StringUtil.isNotEmpty(regionalism)) {
            List<String> infoList = analysisDao.selectInfoIds(techid,casetype,regionalism);
            if(!infoList.isEmpty()) {
                analysisSuggestion.setInfoids(infoList.get(0));
            }
        }
        if(StringUtils.isEmpty(analysisSuggestion.getInfoids())){
            if(StringUtil.isNotEmpty(casetype)){
                List<String> infoList = analysisDao.selectInfoIds(techid,casetype,"");
                if(!infoList.isEmpty()) {
                    analysisSuggestion.setInfoids(infoList.get(0));
                }
            }
        }
        String deadAmount = caseDetail.getDead_amount();
        //死亡数量大于1 按14类案件处理
        int deadCount = 0;
        if(!StringUtils.isEmpty(deadAmount)){
            // "^\\d+$" //非负整数（正整数   +   0）
            if(deadAmount.matches("^\\d+$")){
                deadCount = Integer.valueOf(deadAmount);
                if(deadCount>0){
                    analysisSuggestion.setInfoids("");
                }
            }
        }


        if(StringUtil.isNotEmpty(casetype)||StringUtil.isNotEmpty(regionalism)) {
            List<AnalysisVo> analysisVos = analysisDao.selectAnalysisVo(techid,casetype,regionalism);
            if(analysisVos!=null&&analysisVos.size()!=0){
                for (AnalysisVo av: analysisVos) {
                    String temple_typle  = av.getTemple_type();
                    if("侵害目标对象" .equals(temple_typle)){
                        String dict_id = av.getDict_id();
                        String rootKey = "XZDXFLDM";
                        List<Map<String, Object>>  list= sysdictService.selectSysdictByDictId(rootKey,dict_id);
                        if(list!=null&&list.size()!=0){
                            analysisSuggestion.setXzdxfldm(list);
                        }
                    }
                    if("侵害目标处所" .equals(temple_typle)){
                        String dict_id = av.getDict_id();
                        String rootKey = "XZCSFLDM";
                        List<Map<String, Object>>  list= sysdictService.selectSysdictByDictId(rootKey,dict_id);
                        if(list!=null&&list.size()!=0){
                            analysisSuggestion.setXzcsfldm(list);
                        }
                    }
                    if("作案时机" .equals(temple_typle)){
                        String dict_id = av.getDict_id();
                        String rootKey = "ZASJDFLDM";
                        List<Map<String, Object>>  list= sysdictService.selectSysdictByDictId(rootKey,dict_id);
                        if(list!=null&&list.size()!=0){
                            analysisSuggestion.setZasdfldm(list);
                        }
                    }
                    if("作案入口" .equals(temple_typle)){
                        String dict_id = av.getDict_id();
                        String rootKey = "ZACRKDM";
                        List<Map<String, Object>>  list= sysdictService.selectSysdictByDictId(rootKey,dict_id);
                        if(list!=null&&list.size()!=0) {
                            analysisSuggestion.setZacrkdm_r(list);
                        }
                    }
                    if("作案出口" .equals(temple_typle)){
                        String dict_id = av.getDict_id();
                        String rootKey = "ZACRKDM";
                        List<Map<String, Object>>  list= sysdictService.selectSysdictByDictId(rootKey,dict_id);
                        if(list!=null&&list.size()!=0) {
                            analysisSuggestion.setZacrkdm_c(list);
                        }
                    }
                    if("作案手段" .equals(temple_typle)){
                        String dict_id = av.getDict_id();
                        String rootKey = "ZASDFLDM";
                        List<Map<String, Object>>  list= sysdictService.selectSysdictByDictId(rootKey,dict_id);
                        if(list!=null&&list.size()!=0) {
                            analysisSuggestion.setZasdfldm(list);
                        }
                    }
                    if("侵入方式" .equals(temple_typle)){
                        String dict_id = av.getDict_id();
                        String rootKey = "QRFSFLDM";
                        List<Map<String, Object>>  list= sysdictService.selectSysdictByDictId(rootKey,dict_id);
                        if(list!=null&&list.size()!=0) {
                            analysisSuggestion.setQrfsfldm(list);
                        }
                    }
                    if("作案特点" .equals(temple_typle)){
                        String dict_id = av.getDict_id();
                        String rootKey = "ZATDFLDM";
                        List<Map<String, Object>>  list= sysdictService.selectSysdictByDictId(rootKey,dict_id);
                        if(list!=null&&list.size()!=0) {
                            analysisSuggestion.setZatdfldm(list);
                        }
                    }
                    if("案件性质" .equals(temple_typle)){
                        String dict_id = av.getDict_id();
                        String rootKey = "AJXZDM";
                        List<Map<String, Object>>  list= sysdictService.selectSysdictByDictId(rootKey,dict_id);
                        if(list!=null&&list.size()!=0) {
                            analysisSuggestion.setAjxzdm(list);
                        }
                    }
                    if("作案动机目的" .equals(temple_typle)){
                        String dict_id = av.getDict_id();
                        String rootKey = "ZADJMDDM";
                        List<Map<String, Object>>  list= sysdictService.selectSysdictByDictId(rootKey,dict_id);
                        if(list!=null&&list.size()!=0) {
                            analysisSuggestion.setZadjmddm(list);
                        }
                    }
                }
            }
		}
		return analysisSuggestion;
	}

	@Override
	public CommissionTools addOrUpdateTool(CommissionTools commissionTools) {
		if(StringUtil.isNotEmpty(commissionTools.getId())) {
		//update	
			analysisDao.updateCommissiontools(commissionTools);
		}else {
		//add
			Date date = new Date();
			SimpleDateFormat sFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String time = sFormat.format(date);
			commissionTools.setCreate_datetime(time);
			commissionTools.setId(UUIDUtil.getUUID());
			//切换分析意见主id
            commissionTools.setAnalysis_id(analysisDao.selectAnalysisId( commissionTools.getAnalysis_id()));
			analysisDao.addCommissiontools(commissionTools);
		}
		return  commissionTools;
	}

	@Override
	public void deleteTool(CommissionTools commissionTools) {
		analysisDao.deleteCommissiontools(commissionTools);
	}

	@Override
	public void addorupdateAnalysis(AnalysisSuggestion analysisSuggestion,User user) {
		Date date = new Date();
		SimpleDateFormat sFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String time = sFormat.format(date);
        Organize organization = loginDao.selectOrganize(user.getUserCard());
		if(StringUtil.isNotEmpty(analysisSuggestion.getId())) {
			//update
			if(StringUtil.isNotEmpty(analysisSuggestion.getCommission_desc_id())) {
				BigtextClob bigtextClob = new BigtextClob();
				bigtextClob.setId(analysisSuggestion.getCommission_desc_id());
				bigtextClob.setContent(analysisSuggestion.getCommission_desc_content());
				analysisDao.updateAnalysisContent(bigtextClob);
			}else if(StringUtil.isEmpty(analysisSuggestion.getCommission_desc_id())) {
			    if(!StringUtil.isNotEmpty(analysisSuggestion.getCommission_desc_content())){
                    analysisSuggestion.setCommission_desc_content("");
                }
			    BigtextClob bigtextClob = new BigtextClob();
				String id = UUIDUtil.getUUID();
				analysisSuggestion.setCommission_desc_id(id);
				bigtextClob.setId(id);
				bigtextClob.setCreate_datetime(time);
				bigtextClob.setCreate_user(analysisSuggestion.getCreate_user());
				bigtextClob.setContent(analysisSuggestion.getCommission_desc_content());
				analysisDao.addAnalysisContent(bigtextClob);
			}
			
			if(StringUtil.isNotEmpty(analysisSuggestion.getCriminal_points_id())) {
				BigtextClob bigtextClob = new BigtextClob();
				bigtextClob.setId(analysisSuggestion.getCriminal_points_id());
				bigtextClob.setContent(analysisSuggestion.getCriminal_points_content());
				analysisDao.updateAnalysisContent(bigtextClob);
			}else if(StringUtil.isEmpty(analysisSuggestion.getCriminal_points_id())) {
                if(!StringUtil.isNotEmpty(analysisSuggestion.getCriminal_points_content())){
                    analysisSuggestion.setCriminal_points_content("");
                }
			    BigtextClob bigtextClob = new BigtextClob();
				String id = UUIDUtil.getUUID();
				analysisSuggestion.setCriminal_points_id(id);
				bigtextClob.setId(id);
				bigtextClob.setCreate_datetime(time);
				bigtextClob.setCreate_user(analysisSuggestion.getCreate_user());
				bigtextClob.setContent(analysisSuggestion.getCriminal_points_content());
				analysisDao.addAnalysisContent(bigtextClob);
			}
			
			if(StringUtil.isNotEmpty(analysisSuggestion.getBunch_reason_id())) {
				BigtextClob bigtextClob = new BigtextClob();
				bigtextClob.setId(analysisSuggestion.getBunch_reason_id());
				bigtextClob.setContent(analysisSuggestion.getBunch_reason_content());
				analysisDao.updateAnalysisContent(bigtextClob);
			}else if(StringUtil.isEmpty(analysisSuggestion.getBunch_reason_id())) {
                if(!StringUtil.isNotEmpty(analysisSuggestion.getBunch_reason_content())){
                    analysisSuggestion.setBunch_reason_content("");
                }
			    BigtextClob bigtextClob = new BigtextClob();
				String id = UUIDUtil.getUUID();
				analysisSuggestion.setBunch_reason_id(id);
				bigtextClob.setId(id);
				bigtextClob.setCreate_datetime(time);
				bigtextClob.setCreate_user(analysisSuggestion.getCreate_user());
				bigtextClob.setContent(analysisSuggestion.getBunch_reason_content());
				analysisDao.addAnalysisContent(bigtextClob);
			}
			analysisDao.updateAnalysis(analysisSuggestion);
            opSceneAnalysisDao.updateOpAnalysis(analysisSuggestion);
		}else {
			//add
			if(!StringUtil.isNotEmpty(analysisSuggestion.getCommission_desc_content())) {
                analysisSuggestion.setCommission_desc_content("");
			}
            BigtextClob bigtextClob = new BigtextClob();
            String id = UUIDUtil.getUUID();
            analysisSuggestion.setCommission_desc_id(id);
            bigtextClob.setId(id);
            bigtextClob.setCreate_datetime(time);
            bigtextClob.setCreate_user(analysisSuggestion.getCreate_user());
            bigtextClob.setContent(analysisSuggestion.getCommission_desc_content());
            analysisDao.addAnalysisContent(bigtextClob);

			if(!StringUtil.isNotEmpty(analysisSuggestion.getCriminal_points_content())) {
                analysisSuggestion.setCriminal_points_content("");
            }
            bigtextClob = new BigtextClob();
			id = UUIDUtil.getUUID();
            analysisSuggestion.setCriminal_points_id(id);
            bigtextClob.setId(id);
            bigtextClob.setCreate_datetime(time);
            bigtextClob.setCreate_user(analysisSuggestion.getCreate_user());
            bigtextClob.setContent(analysisSuggestion.getCriminal_points_content());
            analysisDao.addAnalysisContent(bigtextClob);

			if(!StringUtil.isNotEmpty(analysisSuggestion.getBunch_reason_content())) {
                analysisSuggestion.setBunch_reason_content("");
            }
            bigtextClob = new BigtextClob();
			id =UUIDUtil.getUUID();
            analysisSuggestion.setBunch_reason_id(id);
            bigtextClob.setId(id);
            bigtextClob.setCreate_datetime(time);
            bigtextClob.setCreate_user(analysisSuggestion.getCreate_user());
            bigtextClob.setContent(analysisSuggestion.getBunch_reason_content());
            analysisDao.addAnalysisContent(bigtextClob);

            analysisSuggestion.setId(UUIDUtil.getUUID());
			analysisSuggestion.setCreate_datetime(time);
            analysisSuggestion.setInit_server_no(organization.getRegionalism());
			analysisDao.addAnalysis(analysisSuggestion);
            analysisSuggestion.setId(UUIDUtil.getUUID());
            opSceneAnalysisDao.addOpAnalysis(analysisSuggestion);
		}

		//处理result;
		String investigationId = analysisSuggestion.getInvestigation_id();
		AnalysisResult analysisResult = new AnalysisResult();
		analysisResult.setInvestigationId(investigationId);

		//METERIALS_RELIED_ON 现场分析依据处理
		String meterials_relied_no = "";
		if(!StringUtils.isEmpty(analysisSuggestion.getMeterials_relied_on())){
			if(analysisSuggestion.getMeterials_relied_on().indexOf("A")!=-1){
				meterials_relied_no = "实地勘验、";
			}
			if(analysisSuggestion.getMeterials_relied_on().indexOf("B")!=-1){
				meterials_relied_no = meterials_relied_no+"现场实验、";
			}
			if(analysisSuggestion.getMeterials_relied_on().indexOf("C")!=-1){
				meterials_relied_no = meterials_relied_no+"调查访问、";
			}
			if(analysisSuggestion.getMeterials_relied_on().indexOf("D")!=-1){
				meterials_relied_no = meterials_relied_no+"检验鉴定、";
			}
		}
		analysisResult.setMeterialsReliedOn(meterials_relied_no);
		//INTENTION_DESC 选则对象描述
		analysisResult.setIntentionDesc(analysisSuggestion.getIntention_cn()+"、"+analysisSuggestion.getIntention_desc()+"、");
		//LOCATION_DESC 选则处所描述
		analysisResult.setLocationDesc(analysisSuggestion.getLocation_cn()+"、"+analysisSuggestion.getLocation_desc()+"、");
		//COMMISSION_PLACE 作案地点
		analysisResult.setCommissionPlace(analysisSuggestion.getCommission_place());
		//PERIOD_DESC 做案时段
		analysisResult.setPeriodDesc(analysisSuggestion.getCommission_period_cn()+"、"+analysisSuggestion.getCommission_period_desc()+"、");
		//EXIT_ENTRANCE_DESC 作案出口描述
		analysisResult.setExitEntranceDesc(analysisSuggestion.getExit_entrance_cn()+"、"+analysisSuggestion.getExit_entrance_desc()+"、");
		//ENTRANCE_EXIT_DESC 作案进出口描述
		analysisResult.setEntranceExitDesc(analysisSuggestion.getEntrance_exit_cn()+"、"+analysisSuggestion.getEntrance_exit_desc()+"、");
		//COMMISSION_MEANS_DESP 作案手段描述
		analysisResult.setCommissionMeansDesp(analysisSuggestion.getCommission_means_cn()+"、"+analysisSuggestion.getCommission_means_desc()+"、");
		//INTRUDING_WAY_DESC 侵入方法描述
		analysisResult.setIntrudingWayDesc(analysisSuggestion.getIntruding_way_cn()+"、"+analysisSuggestion.getIntruding_way_desc()+"、");
		//PERCULIARITIES_DESCRIPTION 作案特点描述
		analysisResult.setPerculiaritiesDescription(analysisSuggestion.getCommission_points_cn()+"、"+analysisSuggestion.getCommission_points_desc()+"、");
		//CASE_PROPERTY_DESC 案件性质描述
		analysisResult.setCasePropertyDesc(analysisSuggestion.getCase_property_cn()+"、"+analysisSuggestion.getCase_property_desc()+"、");
		//MOTIVE_DESC 作案动机目的描述
		analysisResult.setMotiveDesc(analysisSuggestion.getMotivation_cn()+"、"+analysisSuggestion.getMotivation_desc()+"、");
		//CRIMINAL_AMOUNT_DESC 作案人数描述
		String criminal_amount_desc = "";
		if(!StringUtils.isEmpty(analysisSuggestion.getCriminal_amount())) {
			if (analysisSuggestion.getCriminal_amount().indexOf("1") != -1) {
				criminal_amount_desc = "单人" + "、";
			}
			;
			if (analysisSuggestion.getCriminal_amount().indexOf("2") != -1) {
				criminal_amount_desc = "双人" + "、";
			}
			;
			if (analysisSuggestion.getCriminal_amount().indexOf("3") != -1) {
				criminal_amount_desc = "多人" + "、";
			}
			;
			if (analysisSuggestion.getCriminal_amount().indexOf("4") != -1) {
				criminal_amount_desc = "不确定" + "、";
			}
		}
		criminal_amount_desc = criminal_amount_desc + analysisSuggestion.getCriminal_amount_desc()+"";
		analysisResult.setCriminalAmountDesc(criminal_amount_desc);
		//COMMISSION_DESC_ID 做案过程
		analysisResult.setCommissionDescId(analysisSuggestion.getCommission_desc_id());
		//CRIMINAL_POINTS_ID 作案人特点
		analysisResult.setCriminalPointsId(analysisSuggestion.getCriminal_points_id());
		//BUNCH_REASON_ID 并案意见及根据
		analysisResult.setBunchReasonId(analysisSuggestion.getBunch_reason_id());
		//SUGGESTION_ID 工作建议

		String suggestContent = "";
		suggestContent = "1.关于痕迹物证的保管、检验、应用、建库与查询等意见：";
		suggestContent = suggestContent+analysisSuggestion.getSuggestion1()+"；";
		suggestContent = suggestContent+"2.关于现场保留、现场复勘、尸体处理等意见：";
		suggestContent = suggestContent+analysisSuggestion.getSuggestion2()+"；";
		suggestContent = suggestContent+"3.关于侦查方向与范围、侦破措施及途径等意见：";
		suggestContent = suggestContent+analysisSuggestion.getSuggestion3()+"；";
		suggestContent = suggestContent+"4.关于技术防范对策：";
		suggestContent = suggestContent+analysisSuggestion.getSuggestion4()+"；";
		suggestContent = suggestContent+"5.其他：";
		suggestContent = suggestContent+analysisSuggestion.getSuggestion6()+"；";

		//分析人，分析时间，分析单位
		analysisResult.setAnalysedBy(analysisSuggestion.getCreate_user());
		analysisResult.setAnalysedDate(time);
		analysisResult.setAnalysedOrg("");
		analysisResult.setCreateUser(analysisSuggestion.getCreate_user());
		analysisResult.setCreateDatetime(time);
		analysisResult.setUpdateDatetime(time);
		analysisResult.setUpdateUser(analysisSuggestion.getCreate_user());

		AnalysisResult result = analysisDao.selectAnalysisResult(investigationId);
		if(result!=null){
			//update
			if(StringUtils.isEmpty(result.getSuggestionId())){
				BigtextClob bigtextClob = new BigtextClob();
				String id =UUIDUtil.getUUID();
				bigtextClob.setId(id);
				bigtextClob.setCreate_datetime(time);
				bigtextClob.setCreate_user(analysisSuggestion.getCreate_user());
				bigtextClob.setContent(suggestContent);
				//新增大文本
				analysisDao.addAnalysisContent(bigtextClob);
				analysisResult.setSuggestionId(id);
			}else {
				BigtextClob bigtextClob = new BigtextClob();
				bigtextClob.setId(result.getSuggestionId());
				bigtextClob.setContent(suggestContent);
				analysisDao.updateAnalysisContent(bigtextClob);
                analysisResult.setSuggestionId(result.getSuggestionId());
			}
			opSceneAnalysisDao.updateOpAnalysisResult(analysisResult);
            analysisResult = chuLiXiLeiMu(analysisResult,analysisSuggestion);
			analysisDao.updateAnalysisResult(analysisResult);

		}else{
			//add
			BigtextClob bigtextClob = new BigtextClob();
			String id =UUIDUtil.getUUID();
			bigtextClob.setId(id);
			bigtextClob.setCreate_datetime(time);
			bigtextClob.setCreate_user(analysisSuggestion.getCreate_user());
			bigtextClob.setContent(suggestContent);
			//新增大文本
			analysisDao.addAnalysisContent(bigtextClob);
			analysisResult.setSuggestionId(id);
			String resultid =UUIDUtil.getUUID();
			analysisResult.setId(resultid);
            analysisResult.setInitServerNo(organization.getRegionalism());
            opSceneAnalysisDao.addOpAnalysisResult(analysisResult);
            analysisResult = chuLiXiLeiMu(analysisResult,analysisSuggestion);
            analysisResult.setId(UUIDUtil.getUUID());
            analysisDao.addAnalysisResult(analysisResult);

		}
	}

	@Override
	public List<Map<String, String>> selectToolName(String userCard) {
		return analysisDao.selectToolName(userCard);
	}

	@Override
	public void addToolName(Map<String, String> map) {

		analysisDao.addToolName(map);
	}

	@Override
	public void deleteToolName(String id) {
		analysisDao.deleteToolName(id);
	}


    public AnalysisResult chuLiXiLeiMu(AnalysisResult result,AnalysisSuggestion analysisSuggestion){
        //INTENTION_DESC 选则对象描述
        String rootKey="XZDXFLDM";
        String intention = analysisSuggestion.getIntention();
        String[] intentionAll =biaoShi(intention,rootKey);
        String intentionS = intentionAll[0];
        String intentionW = intentionAll[1];
        result.setIntentionDesc(intentionW+analysisSuggestion.getIntention_desc());
        analysisSuggestion.setIntention(intentionS);
        analysisSuggestion.setIntention_cn(intentionW);//最后修改
        //LOCATION_DESC 选则处所描述
        rootKey = "XZCSFLDM";
        String location=analysisSuggestion.getLocation();
        String[] locationAll =biaoShi(location,rootKey);
        String locationS = locationAll[0];
        String locationW = locationAll[1];
        result.setLocationDesc(locationW+analysisSuggestion.getLocation_desc());
        analysisSuggestion.setLocation(locationS);
        analysisSuggestion.setLocation_cn(locationW);
        //PERIOD_DESC 做案时段
        rootKey="ZASJDFLDM";
        String commissionPeriod=analysisSuggestion.getCommission_period();
        String[] commissionPeriodAll =biaoShi(commissionPeriod,rootKey);
        String commissionPerioS = commissionPeriodAll[0];
        String commissionPerioW = commissionPeriodAll[1];
        result.setPeriodDesc(commissionPerioW+analysisSuggestion.getCommission_period_desc());
        analysisSuggestion.setCommission_period(commissionPerioS);
        analysisSuggestion.setCommission_period_cn(commissionPerioW);
        //EXIT_ENTRANCE_DESC 作案出口描述
        rootKey = "ZACRKDM";
        String exitEntrance=analysisSuggestion.getExit_entrance();
        String[] exitEntranceAll =biaoShi(exitEntrance,rootKey);
        String exitEntranceS = exitEntranceAll[0];
        String exitEntranceW = exitEntranceAll[1];
        result.setExitEntranceDesc(exitEntranceW+analysisSuggestion.getExit_entrance_desc());
        analysisSuggestion.setExit_entrance(exitEntranceS);
        analysisSuggestion.setExit_entrance_cn(exitEntranceW);
        //ENTRANCE_EXIT_DESC 作案进出口描述
        rootKey = "ZACRKDM";
        String entranceExit=analysisSuggestion.getEntrance_exit();
        String[] entranceExitAll =biaoShi(entranceExit,rootKey);
        String entranceExitS = entranceExitAll[0];
        String entranceExitW = entranceExitAll[1];
        result.setEntranceExitDesc(entranceExitW+analysisSuggestion.getEntrance_exit_desc());
        analysisSuggestion.setEntrance_exit(entranceExitS);
        analysisSuggestion.setEntrance_exit_cn(entranceExitW);
        //COMMISSION_MEANS_DESP 作案手段描述
        rootKey = "ZASDFLDM";
        String commissionMeans=analysisSuggestion.getCommission_means();
        String[] commissionMeansAll =biaoShi(commissionMeans,rootKey);
        String commissionMeansS = commissionMeansAll[0];
        String commissionMeansW = commissionMeansAll[1];
        result.setCommissionMeansDesp(commissionMeansW+analysisSuggestion.getCommission_means_desc());
        analysisSuggestion.setCommission_means(commissionMeansS);
        analysisSuggestion.setCommission_means_cn(commissionMeansW);
        //INTRUDING_WAY_DESC 侵入方法描述
        rootKey = "QRFSFLDM";
        String intrudingWay=analysisSuggestion.getIntruding_way();
        String[] intrudingWayAll =biaoShi(intrudingWay,rootKey);
        String intrudingWayS = intrudingWayAll[0];
        String intrudingWayW = intrudingWayAll[1];
        result.setIntrudingWayDesc(intrudingWayW+analysisSuggestion.getIntruding_way_desc());
        analysisSuggestion.setIntruding_way(intrudingWayS);
        analysisSuggestion.setIntruding_way_cn(intrudingWayW);
        //PERCULIARITIES_DESCRIPTION 作案特点描述
        rootKey = "ZATDFLDM";
        String commissionPoints=analysisSuggestion.getCommission_points();
        String[] commissionPointsAll =biaoShi(commissionPoints,rootKey);
        String commissionPointsS = commissionPointsAll[0];
        String commissionPointsW = commissionPointsAll[1];
        result.setPerculiaritiesDescription(commissionPointsW+analysisSuggestion.getCommission_points_desc());
        analysisSuggestion.setCommission_points(commissionPointsS);
        analysisSuggestion.setCommission_points_cn(commissionPointsW);
        //CASE_PROPERTY_DESC 案件性质描述
        rootKey = "AJXZDM";
        String caseProperty=analysisSuggestion.getCase_property();
        String[] casePropertyAll =biaoShi(caseProperty,rootKey);
        String casePropertyS = casePropertyAll[0];
        String casePropertyW = casePropertyAll[1];
        result.setCasePropertyDesc(casePropertyW+analysisSuggestion.getCase_property_desc());
        analysisSuggestion.setCase_property(casePropertyS);
        analysisSuggestion.setCase_property_cn(casePropertyW);
        //MOTIVE_DESC 作案动机目的描述
        rootKey = "ZADJMDDM";
        String motivation=analysisSuggestion.getMotivation();
        String[] motivationAll =biaoShi(motivation,rootKey);
        String motivationS = motivationAll[0];
        String motivationW = motivationAll[1];
        result.setMotiveDesc(motivationW+analysisSuggestion.getMotivation_desc());
        analysisSuggestion.setMotivation(motivationS);
        analysisSuggestion.setMotivation_cn(motivationW);
        //修改analysisSuggestion
        analysisDao.updateAnalysis(analysisSuggestion);
        return result;
    }
    //生成需要的字符串
    public String[] biaoShi(String keys,String rootKey){
	    String result[] = new String[2];
        if(!StringUtils.isEmpty(keys)) {
            String[] intentions = keys.split(",");
            for (int i=0;i<intentions.length;i++){
                if(!StringUtils.isEmpty(intentions[i])){
                    int count = sysdictDao.selectCountSysDict(intentions[i],rootKey);
                    if(count>0){
                        //result不变
                        result[0] = (result[0]==null?"":result[0]) + intentions[i] +",";
                        result[1] = (result[1]==null?"":result[1]) + sysdictDao.selectDictValue1(intentions[i],rootKey)+"、";
                    }else{
                        DictVo dictVo = sysdictDao.selectDcitVo(intentions[i],rootKey);
                        if(dictVo.getCount()<1){
                            dictVo = chuLiDcitVo(dictVo,rootKey);
                        }
                        result[0] = (result[0]==null?"":result[0]) + dictVo.getParentKey()+",";
                        result[1] = (result[1]==null?"":result[1]) + dictVo.getDictValue1()+"、";
                    }
                }
            }
            //去重
            result[0] = quChong(result[0],1);
            result[1] = quChong(result[1],2);
        }
	    return result;
    }

    //去重
    public String quChong(String s,int type){
	    String result = "";
        if(type==1){
            String[] strs = s.split(",");
            List<String> list = new ArrayList<String>();
            for (int i=0; i<strs.length; i++) {
                if(!list.contains(strs[i])) {
                    list.add(strs[i]);
                }
            }
            for (String ts:list) {
                result = result + ts +",";
            }
            if(!StringUtils.isEmpty(result)){
                result =  result.substring(0, result.length() -1);
            }
            return result;
        }
        if(type==2){
            String[] strs = s.split("、");
            List<String> list = new ArrayList<String>();
            for (int i=0; i<strs.length; i++) {
                if(!list.contains(strs[i])) {
                    list.add(strs[i]);
                }
            }
            for (String ts:list) {
                result = result + ts +"、";
            }
            if(!StringUtils.isEmpty(result)){
                result =  result.substring(0, result.length() -1);
            }
            return result;
        }
	    return s;
    }

    //递归查询子集
    public  DictVo chuLiDcitVo(DictVo dictVo,String rootKey){
        dictVo = sysdictDao.selectDcitVo(dictVo.getParentKey(),rootKey);
        if(dictVo.getCount()>0){
            return dictVo;
        }else {
            dictVo = chuLiDcitVo(dictVo,rootKey);
        }
	    return  dictVo;
    }

}
